/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
 var search = function(nums, target) {
    let l = 0,r = nums.length-1;

    while(l<=r){
        const mid = Math.floor((l+r)/2);
        const num = nums[mid];

        if(num === target){
            return mid;
        } else if(num > target){
            r= mid -1;
        } else{
            l = mid+1;
        }
    }
    return -1;
};
module.exports = search;